package com.ruoyi.tzzl.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.tzzl.domain.WzPayConfig;
import com.ruoyi.tzzl.mapper.WzPayConfigMapper;
import com.ruoyi.tzzl.service.IWzPayConfigService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 支付配置Service业务层处理
 *
 * @author by caoyong
 * @date 2022/11/17
 **/
@Service
public class WzPayConfigServiceImpl extends ServiceImpl<WzPayConfigMapper, WzPayConfig> implements IWzPayConfigService {
    @Override
    public List<WzPayConfig> selectWzPayConfigList(String type) {
        LambdaQueryWrapper<WzPayConfig> lqw =new LambdaQueryWrapper<>();
      if (ObjectUtils.isNotEmpty(type)){
          lqw.eq(WzPayConfig::getType,type);
      }
        return this.list(lqw);
    }

    /**
     * 修改支付配置
     *
     * @param wzPayConfig
     */
    @Override
    public Boolean updateConfig(WzPayConfig wzPayConfig) {
        WzPayConfig wzPayConfig1 = this.getById(wzPayConfig.getId());
        //友币数目
        if (ObjectUtils.isNotEmpty(wzPayConfig.getFriendc())) {
            wzPayConfig1.setFriendc(wzPayConfig.getFriendc());
        }
        //人民币数额
        if (ObjectUtils.isNotEmpty(wzPayConfig.getMoney())) {
            wzPayConfig1.setMoney(wzPayConfig.getMoney());
        }
        //提现手续费
        if (ObjectUtils.isNotEmpty(wzPayConfig.getServiceCharge())) {
            wzPayConfig1.setServiceCharge(wzPayConfig.getServiceCharge());
        }
        //单笔充值金额
        if (ObjectUtils.isNotEmpty(wzPayConfig.getSingleRecharge())) {
            wzPayConfig1.setSingleRecharge(wzPayConfig.getSingleRecharge());
        }
        //充值兑换友币
        if (ObjectUtils.isNotEmpty(wzPayConfig.getConvertFriendc())) {
            wzPayConfig1.setConvertFriendc(wzPayConfig.getConvertFriendc());
        }
        /**支付配置类型(1-友币比例配置  2-充值配置)*/
        if (ObjectUtils.isNotEmpty(wzPayConfig.getType())){
            wzPayConfig1.setType(wzPayConfig.getType());
        }
        return this.updateById(wzPayConfig1);
    }

    /**
     * 查询友币比例配置
     */
    @Override
    public WzPayConfig friendConfig() {
        LambdaQueryWrapper<WzPayConfig> lqw =new LambdaQueryWrapper<>();
        lqw.eq(WzPayConfig::getType,"1");
        return this.getOne(lqw);
    }
}
